//
//  CommentVM.m
//  WanCaiC8
//
//  Created by tangang on 2018/4/22.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "CommentVM.h"

@implementation CommentVM

- (void)publishWithId:(NSString *)ID andType:(NSInteger)type andContent:(NSString *)Content andCommentType:(NSInteger)CommentType andPic:(NSArray *)pic Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Comment/Publish" Params:@{@"Id":ID,@"Type":[NSNumber numberWithInteger:type],@"CommentType":[NSNumber numberWithInteger:CommentType],@"Content":Content,@"Pictures":pic} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            [SVProgressHUD showSuccessWithStatus:[returnValue objectForKey:@"Desc"]];
            success([CommentModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getWonderfulCommentId:(NSString *)ID andType:(NSInteger)type andCount:(NSInteger)count Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Comment/GetWonderfulComment" Params:@{@"id":ID,@"type":[NSNumber numberWithInteger:type],@"count":[NSNumber numberWithInteger:count]} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([CommentModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getCommentListWithId:(NSString *)ID andType:(NSInteger)type andLast:(NSString *)lastId andPageSize:(NSInteger)pageSize Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Comment/GetCommentList" Params:@{@"id":ID,@"type":[NSNumber numberWithInteger:type],@"lastId":lastId,@"pageSize":[NSNumber numberWithInteger:pageSize]} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([CommentModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)clickLikeWithId:(NSString *)ID andType:(NSInteger)type andOperationType:(NSInteger)operationType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Comment/ClickLike" Params:@{@"Id":ID,@"Type":@(type),@"OperationType":@(operationType)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success(returnValue);
            [SVProgressHUD showSuccessWithStatus:[returnValue objectForKey:@"Desc"]];
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getReplayListWithId:(NSString *)ID andType:(NSInteger)type andLast:(NSString *)lastId Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Comment/GetReplayList" Params:@{@"id":ID,@"type":[NSNumber numberWithInteger:type],@"lastId":lastId,@"pageSize":defaultPageSize} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([CommentModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}



static CommentVM *n_manager=nil;
+ (CommentVM *)manage{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        n_manager=[[CommentVM alloc]init];
    });
    return n_manager;
}

@end
